package com.oriental.manage.controller.specially;

import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.service.specially.MerchContrastService;
import com.oriental.riskfront.api.model.specially.MerchContrastDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Author: yutao
 * Date: 2017/5/8
 * Time: 14:36
 * Desc：
 */
@Controller
@Slf4j
@RequestMapping("informationPush/merchantInfoComPush")
public class MerchContrastController {

    @Autowired
    private MerchContrastService merchContrastService;

    @RequestMapping("init")
    public String init(){
        return "specially/searchMerchContrast";
    }


    @RequestMapping("search")
    @ResponseBody
    public ResponseDTO<Pagination<MerchContrastDto>> search(@RequestBody Pagination<MerchContrastDto> pagination){
        ResponseDTO<Pagination<MerchContrastDto>> responseDTO = new ResponseDTO<>();
        try{
            log.info("特约商户商户信息对比查询请求参数:",pagination);
            MerchContrastDto queryBean = pagination.getQueryBean();
            queryBean.setType("0");
            List<MerchContrastDto> merchContrasts = merchContrastService.queryPage(queryBean);
            if(merchContrasts !=null && merchContrasts.size()>0){
                pagination.setRowCount(merchContrasts.get(0).getRowCount());
            }
            responseDTO.setSuccess(true);
            pagination.setList(merchContrasts);
            responseDTO.setObject(pagination);
        }catch (Exception e){
            log.error("查询异常:",e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("查询异常");
        }
        return responseDTO;
    }

    @RequestMapping("toDetail")
    public String toDetail(){
        return "specially/merchContrastDetail";
    }

    @RequestMapping("queryDetail")
    @ResponseBody
    public ResponseDTO<Pagination<MerchContrastDto>>  queryContranst(@RequestBody MerchContrastDto merchContrast){
        ResponseDTO<Pagination<MerchContrastDto>> responseDTO = new ResponseDTO<>();
        Pagination<MerchContrastDto> pagination = new Pagination();
        try{
            List<MerchContrastDto> merchContrasts = merchContrastService.queryDetail(merchContrast);
            pagination.setList(merchContrasts);
            responseDTO.setObject(pagination);
            responseDTO.setSuccess(true);
        }catch (Exception e){
            log.error("查询特约商户对比明细协查失败:", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("查询失败");
        }
            return responseDTO;
    }



}
